package cn.leetcode;

public class Code415 {
    public static void main(String[] args) {
        String s = addStrings("99", "23");
        System.out.println(s);
    }

    public static String addStrings(String num1, String num2) {
        int length1 = num1.length() - 1;
        int length2 = num2.length() - 1;
        int bit = 0;
        StringBuilder result = new StringBuilder();
        while (0 <= length1 || 0 <= length2) {
            int aa1 = 0;
            int aa2 = 0;
            if(length1 >= 0){
                char c1 = num1.charAt(length1);
                aa1 = c1 - '0';
            }
            if(length2 >= 0){
                char c2 = num2.charAt(length2);
                aa2 = c2 - '0';
            }
            int i = aa1 + aa2 + bit;
            if(i < 10) {
                bit = 0;
                result.append(i);
            }else {
                int i3 = i - 10;
                bit = 1;
                result.append(i3);
            }
            length1--;
            length2--;
        }
        if(bit == 1){
            result.append(bit);
        }
        return result.reverse().toString();
    }
}
